<template>
    <p>
        <a-space>
            <a-button type="primary" @click="handleQuery()">刷新</a-button>
            
        </a-space>
    </p>
    <a-table :dataSource="stations"
             :columns="columns"
             :pagination="pagination"
             @change="handleTableChange"
             :loading="loading">
        <template #bodyCell="{ column, record }">
            <template v-if="column.dataIndex === 'operation'">
            </template>
        </template>
    </a-table>
</template>

<script>
    import { defineComponent, ref, onMounted } from 'vue';
    import {notification} from "ant-design-vue";
    import axios from "axios";

    export default defineComponent({
        name: "station-view",
        setup() {
            const visible = ref(false);
            let station = ref({
                id: undefined,
                name: undefined,
                namePinyin: undefined,
                namePy: undefined,
                createTime: undefined,
                updateTime: undefined,
            });
            const stations = ref([]);
            // 分页的三个属性名是固定的
            const pagination = ref({
                total: 0,
                current: 1,
                pageSize: 10,
            });
            let loading = ref(false);
            const columns = [
                {
                    title: '站名',
                    dataIndex: 'name',
                    key: 'name',
                },
                {
                    title: '站名拼音',
                    dataIndex: 'namePinyin',
                    key: 'namePinyin',
                },
                {
                    title: '站名拼音首字母',
                    dataIndex: 'namePy',
                    key: 'namePy',
                },
            ];


            const handleQuery = (param) => {
                if (!param) {
                    param = {
                        page: 1,
                        size: pagination.value.pageSize
                    };
                }
                loading.value = true;
                axios.get("/business/admin/station/query-list", {
                    params: {
                        page: param.page,
                        size: param.size
                    }
                }).then((response) => {
                    loading.value = false;
                    let data = response.data;
                    if (data.success) {
                        stations.value = data.content.list;
                        // 设置分页控件的值
                        pagination.value.current = param.page;
                        pagination.value.total = data.content.total;
                    } else {
                        notification.error({description: data.message});
                    }
                });
            };

            const handleTableChange = (page) => {
                // console.log("看看自带的分页参数都有啥：" + JSON.stringify(page));
                pagination.value.pageSize = page.pageSize;
                handleQuery({
                    page: page.current,
                    size: page.pageSize
                });
            };

            onMounted(() => {
                handleQuery({
                    page: 1,
                    size: pagination.value.pageSize
                });
            });

            return {
                station,
                visible,
                stations,
                pagination,
                columns,
                handleTableChange,
                handleQuery,
                loading,
            };
        },
    });
</script>
